// web/src/types/chat.ts

// 步骤相关类型
export interface StepItem {
  step: number;
  type: 'thought' | 'tool_call' | 'tool_result' | 'finish' | 'error';
  content?: string;
  tool_name?: string;
  arguments?: any;
  result?: string;
  status?: 'pending' | 'running' | 'completed' | 'failed';
  images?: string[];
}

export interface StepCard {
  stepId: number;
  thought: string;
  tool_name: string;
  args: any;
  result: string;
  status: 'pending' | 'running' | 'completed' | 'failed';
  images: string[];
}

// 消息相关类型
export interface ChatMessage {
  id: number | string;
  conversation_id: number;
  role: 'user' | 'assistant';
  content: string;
  created_at?: string;
  steps?: StepItem[];
  meta_data?: any;
}

export interface StreamEvent {
  type: 'thought' | 'tool_call' | 'tool_result' | 'finish' | 'error';
  step?: number;
  content?: string;
  tool_name?: string;
  arguments?: any;
  result?: string;
  status?: string;
  images?: string[];
}

// 对话相关类型
export interface Conversation {
  id: number;
  user_id: number;
  title: string;
  mode: 'chat' | 'task_runner';
  status: '进行中' | '已完成' | '失败';
  execution_id?: string;
  meta_data?: any;
  model_name?: string;
  created_at: string;
  updated_at: string;
}

// 历史记录类型
export interface HistoryItem {
  id: number | string;
  title: string;
  createdAt: Date;
  status: 'completed' | 'failed' | 'running' | 'interrupted';
  messageCount?: number;
  lastMessage?: string;
}

// 用户类型
export interface User {
  id: number;
  username: string;
  email: string;
  avatar?: string;
}

// 状态管理类型
export interface ChatState {
  currentConversation: Conversation | null;
  messages: ChatMessage[];
  historyList: HistoryItem[];
  isLoading: boolean;
  isSending: boolean;
  streamError: string | null;
  hasMoreMessages: boolean;
  currentPage: number;
}

// API 响应类型
export interface ApiResponse<T = any> {
  code: string;
  message: string;
  data: T;
  errors?: any;
}

export interface PaginationParams {
  page: number;
  per_page: number;
}

export interface MessagesResponse {
  messages: ChatMessage[];
  pagination: {
    current_page: number;
    total_pages: number;
    total_count: number;
    has_more: boolean;
  };
}

// 工具调用相关类型
export interface ToolCall {
  id: string;
  name: string;
  arguments: Record<string, any>;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  result?: any;
  error?: string;
  created_at?: string;
  completed_at?: string;
  execution_time?: number;
}

export interface ToolExecutionLog {
  step: number;
  tool_name: string;
  arguments: any;
  status: string;
  result_preview?: string;
  timestamp: number;
}

// 组件 Props 类型
export interface ChatSidebarProps {
  user: User | null;
  historyList: HistoryItem[];
  currentConversationId?: number | null;
  loading?: boolean;
}

// 组件 Emits 类型
export interface ChatSidebarEmits {
  (e: 'select-history', id: number): void;
  (e: 'delete-history', id: number): void;
  (e: 'clear-history'): void;
  (e: 'view-all'): void;
  (e: 'replay', item: HistoryItem): void;
  (e: 'download', item: HistoryItem): void;
  (e: 'download-all'): void;
  (e: 'download-stats'): void;
  (e: 'new-chat'): void;
}
